/**
 * @returns 对pc端添加指定样式
 */
export const setPcClass = () => {
  if (verifyPc()) {
    const body = document.querySelector("html");
    body.className += " custom-pc";
  }
};

/**
 * @returns 路由跳转参数装换
 */
export const transitionParams = (params = {}, url = "", row = {}) => {
  const arr = [];
  Object.keys(params).forEach(key => {
    arr.push(`${key}=${params[key] ?? row[key] ?? ""}`);
  });
  return url + "?" + arr.join("&");
};

/**
 * @description 处理  元素隐式具有 “any“ 类型，因为类型为 “string“ 的表达式不能用于索引类型 “Object“
 * */
export const isValidKey = (key: string | number | symbol, object: object): key is keyof typeof object => {
  return key in object;
};

/**
 * @description: 设置默认值
 * @param {string} value
 */
export const setDefault = <T = string>(value: T) => (value ? value : "--");

/**
 * @description: 添加单位
 * @param {string} str
 * @param {string} unit
 * @return {*}
 */
export const addUnit = (str: string | number, unit: string = "KG") => str + unit;
